﻿using System;
using System.Collections.Generic;
using BotonJXC.Entity;
using DepartmentDAO = BotonJXC.DAO.DepartmentDAO;
using BotonJXC.Util;
using NHibernate.Criterion;

namespace BotonJXC.BLL
{
    public class DepartmentBLL : BaseBLL<DepartmentDAO, Department, int>
    {
        public DepartmentBLL()
        {
        }

        public PageModel<Department> Find(string depName, int storeId, short depLevel, int start, int count)
        {
            List<ICriterion> criterions = new List<ICriterion>();
            if (!string.IsNullOrEmpty(depName))
            {
                criterions.Add(Restrictions.Like("DepName", depName, MatchMode.Anywhere));
            }
            if (storeId > 0)
            {
                criterions.Add(Restrictions.Eq("Store.StoreId", storeId));
            }
            if (depLevel > 0)
            {
                criterions.Add(Restrictions.Eq("DepLevel", depLevel));
            }
            return Dao.FindByPage(criterions.ToArray(), null, start, count);
        }

        public IList<Department> FindByStore(params int[] storeIds)
        {
            List<ICriterion> criterions = new List<ICriterion>();

            if (storeIds != null && storeIds.Length > 0)
            {
                criterions.Add(Restrictions.In("Store.StoreId", storeIds));
            }
            return Dao.Find(criterions.ToArray());
        }
    }
}